package cn.gs;

import cn.gs.aspects.LogAspect;
import cn.gs.service.IJDKProxyService;
import cn.gs.service.impl.CglibProxyDemoServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class MyApp {


    public static void main(String[] args) {
        //测试 Spring AOP 注解
        ApplicationContext context =
                new AnnotationConfigApplicationContext(LogAspect.class);

        System.out.println("===============测试 JDK 动态代理================");
        IJDKProxyService ijdkProxyService = context.getBean(IJDKProxyService.class);
        System.out.println("Bean实际类型：" + ijdkProxyService.getClass().getName());
        ijdkProxyService.doMehtod1();
        ijdkProxyService.doMehtod2();

        try {
            ijdkProxyService.doMehtod3();
        } catch (Exception e) {
            System.out.println("异常通知："+e.getMessage());
        }

        System.out.println("===============测试 CGLIB 代理================");
        //测试 CGLIB 代理
        CglibProxyDemoServiceImpl iCGlibProxyService = context.getBean(CglibProxyDemoServiceImpl.class);
        System.out.println("Bean实际类型：" + iCGlibProxyService.getClass().getName());
        iCGlibProxyService.doMehtod1();
        iCGlibProxyService.doMehtod2();

        try {
            iCGlibProxyService.doMehtod3();
        } catch (Exception e) {
            System.out.println("异常通知："+e.getMessage());
        }

    }
}
